var ejs=require("ejs");
var fs=require("fs");
var app={
    login:function (req,res) {
        console.log("login");
        // res.end("login");
        ejs.renderFile("views/form.ejs",{},function (err,data) {
            res.end(data);
        })

    },
    register:function (req,res) {
        console.log("register");
        res.end("register");
    },
    dologin:function (req,res) {
        // console.log("dologin");
        // res.end("dologin");
        var postStr="";
        req.on("data",function (chunk) {
            postStr+=chunk;
        });
        req.on("end",function ( chunk) {
            // res.end(postStr);
            console.log(postStr);
            fs.appendFile("login.txt",postStr+"\n",function (err) {
                if (err){
                    console.log(err);
                    return
                }else {
                    console.log("写入数据成功");
                }

            });
            res.end("<script>alert('login');history.back();</script>");
        })

    },
    index:function (req,res) {
        console.log("index");
        res.end("index");
    }
};
module.exports.app=app;